package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;

import com.elinkway.infinitemovies.async.MoviesHttpAsyncTask;
import com.elinkway.infinitemovies.bean.IsFavoriteBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.IsFavoriteParser;
import com.elinkway.infinitemovies.http.requestInterface.RequestCommonInterface;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by xiaojian on 16-3-14.
 */

public class RequestIsAddFavoriteTask extends MoviesHttpAsyncTask<IsFavoriteBean> {

    private Context context;
    private RequestCommonInterface<IsFavoriteBean> mRequestCommonInterface;
    private String relatedid;
    private String type;
    @Override
    public void netNull() {
        super.netNull();
        mRequestCommonInterface.netError(MoviesHttpApi.IS_FAVORITE_SYNC);
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        super.netErr(updateId, errMsg);
        mRequestCommonInterface.netError(MoviesHttpApi.IS_FAVORITE_SYNC);
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
        mRequestCommonInterface.requestFail(MoviesHttpApi.IS_FAVORITE_SYNC);
    }

    public RequestIsAddFavoriteTask(Context context, String relatedid, String type) {
        super(context);
        this.context = context;
        this.relatedid = relatedid;
        this.type = type;
    }

    public void setRequestListener(RequestCommonInterface<IsFavoriteBean> requestCommonInterface) {
        this.mRequestCommonInterface = requestCommonInterface;
    }

    @Override
    public LVideoDataHull<IsFavoriteBean> doInBackground() {
        LVideoDataHull<IsFavoriteBean> ret = MoviesHttpApi.isfavoriteSyncRequest(
                new IsFavoriteParser(), relatedid, type);
        return ret;
    }

    @Override
    public void onPostExecute(int updateId, IsFavoriteBean result) {
        if(result != null && "200".equals(result.getCode())) {
            mRequestCommonInterface.requestSuccess(updateId, result, MoviesHttpApi.IS_FAVORITE_SYNC);
        }else {

        }
    }
}